home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-20
/
ccdsrc.zip
/
SPEC.C
< prev
Wrap
Text File
|
1991-09-01
|
3KB
|
130 lines
/* Remove speckles from uosat pics
31JUL91 NK6K
Use after pacout and inter
Get a line. See if a pixel is more than 20 different from its neighbors.
If so, make it the average of its neighbors.
Also remove horizontal bar.
NOTE: This algorithm not very good, but serves to make the images
a little better.
*/
#include <stdio.h>
#include <dos.h>
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#define LINE_SIZE 612
#define NUM_LINE_FIELD 288
long start_field_2;
int lines=0;
int skip_lines=0;
int correct;
int correct_fudge=0;
long doubles=0;
unsigned char buff[LINE_SIZE+1];
int fillval=0;
long fixed=0;
int correct_array[10] = {0,5,5,5,5,5,5,5,5,5};
main(argc,argv)
int argc;
char *argv[];
{
int fi1,fi2,fo;
int i;
if (argc<2) {
printf ("usage: spec input output val\n");
exit(1);
}
if ((fi1= open(argv[1], O_BINARY)) == -1){
printf("cannot open: %s\n",argv[1]);
perror("On input file");
exit(1);
}
if ((fo = open(argv[2], 0)) != -1){
printf("output file exists. Aborted\n");
exit(1);
}
if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
printf("cannot open: %s\n",argv[2]);
perror("On output file");
exit(1);
}
while (1) { /* Do till there isn't any more */
if (read(fi1, buff, LINE_SIZE)<LINE_SIZE) {
break;
}
for (i=45;i<LINE_SIZE-1;i++) {
if ( (abs((int)buff[i]-(int)buff[i-1])>20) &&
(abs((int)buff[i]-(int)buff[i+1])>20)) {
/*printf("line %u:%u (%x %x %x)\n",lines,i,
buff[i-1],buff[i],buff[i+1]);*/
/* check to see if the next pixel isn't a better
candidate */
if ( ( abs((int)buff[i+1]-(int)buff[i-1]) ) >
( abs((int)buff[i]-(int)buff[i-1]))) {
doubles++;
}
else {
fixed++;
buff[i] = ((unsigned int)buff[i-1]+(unsigned int)buff[i+1])/2;
}
}
}
if (buff[34]!=0) {
correct=buff[34];
for (i=0;i<10;i++) correct+=buff[34+i];
correct/=10;
correct+=correct_array[correct_fudge];
correct_fudge++;
for (i=34;i<LINE_SIZE-1;i++) {
if ( ((int) buff[i] - (int) correct)>0)
buff[i] = (int) buff[i] - (int) correct ;
else buff[i]=0;
}
}
if (write(fo,buff,LINE_SIZE)==-1) {
perror("On output file\n");
exit(1);
}
/* printf("Line %u fixed %u \r",lines,fixed);*/
lines++;
}
printf("Fixed %lu, doubles %lu\n",fixed,doubles);
close (fo);
close (fi1);
}